<#include "/default/layout/list.htm"/> 
<@layout>
<#if error_message?exists>
    <div class="alert alert-danger">
        ${error_message}
    </div>
</#if>

<section class="main-content">
	<div class="content-wrap">
		<section class="panel panel-default">
			<div class="panel-heading">
				<b>招聘申请</b>
				<small class="pull-right">
					<a href="javascript:javascript:history.go(-1);" class="pd-r-xs"><i class="fa fa-reply"></i> 返回</a>
					<a href="javascript:window.location.reload();" class="pd-r-xs"><i class="fa fa-refresh"></i> 刷新</a>
				</small>
			</div>
			<div class="panel-body">
				<form class="form-horizontal" action="${ctx}/oa/position/save" method="post" id="form">
					<div class="form-group">
						<label class="col-sm-4 control-label">职位标题:</label>
						<div class="col-sm-4 col-md-6">
							${position.title}
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-4 control-label">职能类型:</label>
						<div class="col-sm-4 col-md-6 ">
							<select disabled="disabled" class="form-control input-sm" id="depName" value="${position.depName}" >
								<option value="技术">研发与技术</option>
								<option value="产品">产品与设计</option>								
								<option value="生产">生产与工程</option>								
								<option value="市场">市场与运营</option>
								<option value="物流">物流与客服</option>	
								<option value="管理">管理</option>
								<option value="职能">职能与服务</option>
							</select>
						</div>
					</div>					
					
					<div class="form-group">
						<label class="col-sm-4 control-label">职位描述:</label>
						<div class="col-sm-4 col-md-6">
							${position.jobDescription!}
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-4 control-label">职位要求:</label>
						<div class="col-sm-4 col-md-6">
							${position.jobRequirement!}
						</div>
					</div>
					
					<div class="form-group">
						<label class="col-sm-4 control-label">学历要求:</label>						

						<div class="col-sm-4 col-md-6 ">
							<select disabled="disabled" class="form-control input-sm" id="degree_required" value="${position.degree_required}">
								<option value="0">不限</option>
								<option value="1">大专及以上</option>
								<option value="2">本科及以上</option>
								<option value="3">硕士及以上</option>
								<option value="4">博士及以上</option>
							</select>
						</div>
					</div>
					
					<div class="form-group">
						<label class="col-sm-4 control-label">薪资范围(年薪):</label>
						<div class="col-sm-2 col-md-3">
							${position.min_show_annual_salary!} - ${position.max_show_annual_salary!}
						</div>								
					</div>
					<div class="form-group">
						<label class="col-sm-4 control-label">薪资说明:</label>
						<div class="col-sm-4 col-md-6">
							${position.salaryDescription!}
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-4 control-label">招聘开始时间:</label>
						<div class="col-sm-2 col-md-3">
							${position.startTime!}
						</div>
						<div class="col-sm-2 col-md-3">
							${position.endTime!}
						</div>						
					</div>
					<div class="form-group">
						<label class="col-sm-4 control-label">招聘数目:</label>
						<div class="col-sm-4 col-md-6 ">
							${position.headCount}
						</div>
					</div>
					
				</form>
			</div>
		</section>
	</div>
</section>



<div id="toolbar" class="btn-group">
    <button id="btn_add" type="button" class="btn btn-outline btn-default">
        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
    </button>
    <button id="btn_edit" type="button" class="btn btn-outline btn-default">
        <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
    </button>
    <button id="btn_delete" type="button"
            class="btn btn-outline btn-default ">
        <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
    </button>

</div>

<!-- 列表 -->
<table id="table" data-mobile-responsive="true">

</table>

<!-- 添加，修改弹出框 -->
<div class=" modal   fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" data-backdrop="false" aria-hidden="true"
     data-keyboard="true" data-show="true">
    <div class="modal-dialog " role="document">
        <div class="modal-content">
            <form id="form" class="m-t" role="form" action="/app/save"
                  method="post" autocomplete="off">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close" aria-hidden="true">
                        <span>×</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">新增候选人</h4>
                </div>
                <div class="modal-body">

                    <div class="form-group">
                        <input type="hidden" name="app.app_id" class="form-control"
                               id="resume.id" placeholder="候选人ID">
                    </div>
                    <div class="form-group">
                        <input type="hidden" name="app.app_key" class="form-control"
                               id="resume.phone" placeholder="候选人手机">
                    </div>
                    <div class="form-group">
                        <label for="txt_departmentname">候选人名称</label> <input type="text"
                                                                            name="resume.name" class="form-control" id="resume.name"
                                                                            placeholder="候选人名称"  required="" aria-required="true">
                    </div>

                    <div class="form-group">
                        <label for="txt_departmentname">候选人公司</label> <input type="text"
                                                                            name="resume.companyName" class="form-control" id="resume.companyName"
                                                                            placeholder="候选人公司"  required="" aria-required="true">
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭
                    </button>
                    <button type="button" id="btn_submit" class="btn btn-primary"
                            data-dismiss="modal">
                        <span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>


<script type="text/javascript">
    toastr.options.positionClass = 'toast-top-right';
    
    $(document).ready(function(){  
    	$("#depName").find("option[value=${position.depName}]").attr("selected","selected"); 
		$("#degree_required").find("option[value=${position.degree_required}]").attr("selected","selected");    
     })  

    $(function() {

        //1.初始化Table
        var oTable = new TableInit();
        oTable.Init();

        //2.初始化Button的点击事件
        var oButtonInit = new ButtonInit();
        oButtonInit.Init();

    });

    var TableInit = function() {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function() {
            $('#table').bootstrapTable({
                url : '/oa/position/match-list/${position.id}', //请求后台的URL（*）
                method : 'post', //请求方式（*）
                contentType : "application/x-www-form-urlencoded",
                toolbar : '#toolbar', //工具按钮用哪个容器
                striped : true, //是否显示行间隔色
                cache : false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination : true, //是否显示分页（*）
                sortable : false, //是否启用排序
                sortOrder : "asc", //排序方式
                queryParams : oTableInit.queryParams,//传递参数（*）
                sidePagination : "client", //分页方式：client客户端分页，server服务端分页（*）
                pageNumber : 1, //初始化加载第一页，默认第一页
                pageSize : 20, //每页的记录行数（*）
                pageList : [ 10, 25, 50, 100 ], //可供选择的每页的行数（*）
                iconSize : "outline",
                strictSearch : true,
                showRefresh : true, //是否显示刷新按钮
                showColumns : true,
                clickToSelect : true, //是否启用点击选中行
                //height : 500, //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId : "id", //每一行的唯一标识，一般为主键列
                cardView : false, //是否显示详细视图
                detailView : false, //是否显示父子表
                queryParams : function(params) {
                    var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的

                        pageSize : params.limit, //页面大小
                        pageNumber : params.offset, //页码
                    };
                    return temp;
                },
                columns : [ {
                    field : 'id',
                    checkbox : true,
                    //formatter : stateFormatter
                }, {
                    field : 'name',
                    title : '名称',
                    editable : true
                },
                {
                    field : 'jobTitle',
                    title : '职位',
                    editable : true
                },{
                    field : 'companyName',
                    title : '公司',
                    editable : true
                },                
                {
                    field : 'birthYear',
                    title : '出生'                   
                } ,{
                    field : 'createTime',
                    title : '创建时间',
                    editable : false
                } ]
            });
        };

        function stateFormatter(value, row, index) {
         	return value;
        }

        return oTableInit;
    };

    var ButtonInit = function() {
        var oInit = new Object();
        var postdata = {};

        oInit.Init = function() {
            //初始化页面上面的按钮事件

            $("#btn_add").click(function() {
                $("input").val("");
                $("#myModalLabel").text("新增");
                $('#myModal').modal();
            });

            $("#btn_edit").click(
                    function() {
                        var arrselections = $("#table").bootstrapTable('getSelections');
                        if (arrselections.length < 1) {
                            toastr.warning('请选择一条数据');
                            return;
                        }

                        if (arrselections.length > 1) {
                            toastr.warning('只能选择一行进行编辑');
                            return;
                        }
                        $("#myModalLabel").text("编辑");
                        $("#resume.id").val(arrselections[0].id);
                        $("#resume.phone").val(arrselections[0].phone);
                        $("#resume.name").val(arrselections[0].name);
                        $("#resume.companyName").val(arrselections[0].companyName);
                        $('#myModal').modal();
                    });

            $("#btn_submit").click(
                    //alert("修改、添加");
                    function() {
                        if(!$("#form").valid()){
                            return;
                        }
                        $.ajax({
                            type : "post",
                            url : "/oa/candidate/receive",
                            data : $('#form').serialize(),
                            success : function(data, status) {

                                if (data.result == "success") {
                                    swal("修改成功！", "修改成功。", "success");
                                    $("#table").bootstrapTable('refresh');
                                } else {
                                    swal("修改失败！", "修改失败。", "error");
                                }
                            },
                            error : function() {
                                toastr.error('Error');
                            },
                            complete : function() {

                            }

                        });
                    });

            $("#btn_delete").click(
                    function() {
                        //alert("删除");
                        var arrselections = $("#table").bootstrapTable('getSelections');
                        if (arrselections.length < 1) {
                            toastr.warning('请选择至少一条数据');
                            return;
                        }

                        swal({
                            title : "您确定要删除这条信息吗",
                            text : "删除后将无法恢复，请谨慎操作！",
                            type : "warning",
                            showCancelButton : true,
                            confirmButtonColor : "#DD6B55",
                            confirmButtonText : "是的，我要删除！",
                            cancelButtonText : "让我再考虑一下…",
                            closeOnConfirm : false,
                        }, function() {
                            $.ajax({
                                type : "post",
                                url : "/oa/candidate/delete",
                                data : {
                                    "data" : JSON.stringify(arrselections)
                                },
                                success : function(data, status) {
                                    if (data.result == "success") {
                                        swal("删除成功！", "您已经永久删除了这条信息。",
                                                "success");
                                        $("#table").bootstrapTable('refresh');
                                    }
                                },
                                error : function() {
                                    toastr.error('Error');
                                },
                                complete : function() {

                                }

                            });

                        });

                    });
        };
        return oInit;
    };
</script>

<!--end页面内容  -->
<#macro greet> </#macro> 

</@layout>
